#ifndef FORM_GZLTJ_H
#define FORM_GZLTJ_H

#include <QWidget>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QPrinter>
#include <QPainter>
#include "mysqlmodel.h"
#include "pub_pop_get_date.h"
#include "pub_pop_delay.h"
#include <QSqlQueryModel>
#include <QComboBox>

namespace Ui {
class Form_gzltj;
}

class Form_gzltj : public QWidget
{
    Q_OBJECT

public:
    explicit Form_gzltj(QWidget *parent = nullptr);
    ~Form_gzltj();

signals:
    void destroyW( QString );

private slots:
    void closeEvent(QCloseEvent *event);

    void add_cbb_to_le(QComboBox *, QLineEdit *);
    QString get_code_from_str(QString base, QString cbb, QString le);
    QStringList get_fields(QString sql, QString field_name, QString &);
    bool create_temp_table(QStringList flds);

    void on_pbExit_clicked();
    void on_pbRun_clicked();

    void printOutExcel(QJsonArray);
    void printOutDirect(QJsonArray);
    void printPageBase();
    QRectF getRealPosition(int, int);

    void writeCell(int row, int col, QString val, QString item_name, QJsonArray &ja);
    void preparePrintData(QJsonArray &jaa, QJsonArray &jat, QString dt1, QString title ,QString tf);


    void on_pbBalance_clicked();

    void on_pbPrintOut_clicked();

    void on_tabWidget_currentChanged(int index);

    void on_pbQuery_clicked();

    void on_pbQuery_2_clicked();

    void on_pbQuery_3_clicked();

    void on_pbQuery_4_clicked();

    void on_rbWrj_clicked();

    void on_rbBr_clicked();

    void on_pbQuery_5_clicked();

    void on_pbPrintCount_clicked();

    void on_tb_begin_clicked();

    void on_tb_end_clicked();

    void on_pb_run_fee_detail_clicked();

    void on_cbb_dept_fee_detail_currentTextChanged(const QString &arg1);

    void on_tb_add_dept_clicked();

    void on_pb_clear_condition_clicked();

    void on_tb_add_doct_clicked();

    void on_tb_add_type_clicked();

    void on_pb_export_to_excel_clicked();

    void on_rb_title_normal_clicked();

    void on_rb_title_dept_clicked();

    void on_rb_title_item_clicked();

    void on_pb_count_export_clicked();

private:
    Ui::Form_gzltj *ui;
    QSqlQuery * qro, *qrot, *qrm, *qrmp;

    pub_pop_get_date * dlg_get_date;
    Pub_pop_delay * dlg_delay;

    QSqlQueryModel mdList ;  //项目明细列表
    MySqlModel *mmdList;

    QSqlQueryModel *md_fee_detail ;  //

    QString dt1g,dt1s,dt2;    //结账起止时间
    QString ghtf, sktf;  //挂号退费明细，收款退费明细
    QJsonArray jatg,jats; //临时数据-挂号，临时数据-收费，
    QString sq;

    QPrinter *prt;      //打印机
    QPainter *pnt;
    double xPos,yPos;      //页面坐标偏移
    float ptScale;  //for printer, mm to point covnert.
    float margin;   //边界

    QMap<QString,QString> oper_code;
    QMap<QString,QString> dept_code;
    QMap<QString,QString> insutype_code;

    QString sql_for_print;  //打印统计表使用的 sql

    bool privFinance;   //财务权限
    bool initial_finished; //界面初始化
    QString fee_code_rela, dept_code_rela, doct_code_rela; //费用名称与编码，诊室与编码,医生与编码

    QString last_sql; //最后执行的sql，用于导出数据
};

#endif // FORM_GZLTJ_H
